package ic.distribution.controller;

import IC.common.core.domain.R;
import IC.common.core.web.controller.BaseController;
import IC.common.core.web.page.TableDataInfo;
import com.github.pagehelper.PageInfo;
import ic.distribution.config.OssUtil;
import ic.distribution.config.OssUtil2;
import ic.distribution.domain.DTO.DefenseDTO;
import ic.distribution.domain.Defense;
import ic.distribution.domain.PO.DefensePO;
import ic.distribution.domain.VO.DefenseVo;
import ic.distribution.domain.Vehicle;
import ic.distribution.domain.result.PageResult;
import ic.distribution.domain.result.Result;
import ic.distribution.service.DesenseService;
//import jdk.nashorn.internal.objects.annotations.Constructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
public class DistributionController extends BaseController {

    @Autowired
    private DesenseService service;


    @PostMapping("/upload")
    public R<String> upload(@RequestBody MultipartFile file)
    {
        String url = OssUtil.uploadMultipartFile(file);
        return R.ok(url);
    }

    @PostMapping("/urlTobase64")
    public String urlTobase64(String imageUrl)
    {
        return OssUtil2.imageUrlToBase64(imageUrl);
    }

    @PostMapping("/add")
    public R add(@RequestBody DefensePO defensePO)
    {
        service.add(defensePO);
        return R.ok();
    }

    @GetMapping
    public R ScheduledDel()
    {
        service.ScheduledDel();
        return R.ok();
    }

    /**
     * 布控列表
     */
    @PostMapping("/findefense")
    public R DesenseList(@RequestBody DefenseVo defenseVo)
    {

        PageInfo<Defense> list=service.desenselist(defenseVo);
        return R.ok(list);
    }


    @GetMapping("/effective")
    public R<List<Defense>> effective()
    {
        List<Defense> list=service.effective();
        return R.ok(list);
    }

    /**
     * 修改布控
     */
    @PostMapping("/update")
    public R update(@RequestBody DefenseDTO defenseDTO)
    {
        service.update(defenseDTO);
        return R.ok();
    }


    /**
     * 撤销布控
     */
    @GetMapping("/updstatu/{id}")
    public R updstatu(@PathVariable Integer id)
    {
        service.updstatu(id);
        return R.ok();
    }

    /**
     * 一键布控
     */
    @GetMapping("/updstatu2/{id}")
    public R updstatu2(@PathVariable Integer id)
    {
        service.updstatu2(id);
        return R.ok();
    }

    /**
     * 一键开启
     * @return
     */
    @GetMapping("/cherkAll")
    public R open(){
        service.cherkAll();
        return R.ok();
    }

    /**
     * 一键暂停
     * @return
     */
    @GetMapping("/cherkPause")
    public R cherkPause(){
        service.cherkPause();
        return R.ok();
    }

    @GetMapping("/togetcount")
    public R<Integer> togetcount(){
        Integer togetcount = service.togetcount();
        return R.ok(togetcount);
    }


}
